package com.example.bootdemo.utils;

import com.alibaba.fastjson.JSONArray;
import com.example.bootdemo.dao.StudentDao;
import com.example.bootdemo.model.Student;
import org.junit.Test;

import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

public class ReadLocalJsonFileDemo {
    @Resource
    StudentDao studentDao;
    public static void main(String[] args) throws IOException {
        File file = new File("D:\\qrCode\\bb\\json.txt");
        //nioMethod(file);
    }
    @Test
    public  void insert() throws IOException {
        File file = new File("D:\\qrCode\\bb\\json.txt");
        nioMethod(file);
    }
    private   void nioMethod(File file) throws IOException {
        String jsonString = new String(Files.readAllBytes(Paths.get(file.getPath())));

        List<Student> list=    JSONArray.parseArray(jsonString, Student.class);

       for (Student student:list ) {
            System.out.println(student);

           studentDao.insert(student);
        }/* */
    }
}